<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>红包大派送</title>
        <link rel="stylesheet" href="__STATIC__/web/index/redpacket/css/redbox.css">
        <script src="__STATIC__/web/index/redpacket/js/public.js"></script>
        <script src="__STATIC__/web/index/redpacket/js/jquery-3.1.1.min.js"></script>
        <style>
            /*小程序二维码弹窗*/
            .codepop {
                width: 100%;
                height: 100%;
                background: rgba(0, 0, 0, 0.5);
                position: fixed;
                top: 0;
                z-index: 999999999;
            }
            .imgcodeBox {
                width: 12.224rem;
                height: 15.78666667rem;
                position: fixed;
                top: 50%;
                margin-top: -8.89333333rem;
                left: 50%;
                margin-left: -6.112rem;
                background: url(__STATIC__/web/H5/item/img/codebg.png) no-repeat center;
                background-size: cover;
            }
            #imgcode {
                display: block;
                width: 4.97066667rem;
                height: 4.97066667rem;
                margin: 0 auto;
                margin-top: 8.21333333rem;
            }
            .closecodepop {
                display: block;
                width: 1.152rem;
                height: 1.152rem;
                margin: 0 auto;
                margin-top: 1.94133333rem;
            }
            .longPressLook {
                font-size: 0.59733333rem;
                color: #828282;
                text-align: center;
                margin-top:.8rem;
            }

        </style>
    </head>
    <body>
            <div id="box" onclick="whetherOpen()">
                <!--<input type="image" src="__STATIC__/web/index/redpacket/images/redenvelops_btn@2x.png">-->
            </div>
    </body>
    <script>
        var dialog = {
            getAlertTemplate: function () {
                var temp =
                        '<div class="imgcodeBox">' +
                        '<img id="imgcode" alt="" src="">' +
                        '<div class="longPressLook">长按识别查看详情</div>' +
                        '<img class="closecodepop" id="closepop" alt="" src="__STATIC__/web/H5/item/img/closepop.png">' +
                        '</div>';
                return temp;
            },
            alert: function (imgsrc) {
                document.body.classList.add('fixed');
                var boxs = document.createElement("div"),
                        _this = this;
                boxs.className = 'codepop';
                boxs.innerHTML = this.getAlertTemplate();
                function move(e) {
                    e.preventDefault();//禁止事件冒泡
                }
                $(boxs).on('touchmove', move, false)//弹出层出现，弹出层的背景层阻止默认滑动事件  
                this.boxs = boxs;
                document.body.appendChild(boxs);
                var imgcode = document.getElementById("imgcode");
                console.log(imgcode)
                imgcode.src = imgsrc;
                var btn = document.getElementById('closepop');
                console.log(btn)

                btn.addEventListener('click', function () {
                    var boxs = document.getElementsByClassName('codepop');
                    console.log(boxs[0])
                    document.body.removeChild(boxs[0]);
                })
            },
            removeBoxs: function () {
                var boxs = document.getElementsByClassName('imgcodeBox');
                document.body.removeChild(boxs[0]);
                document.body.classList.remove('fixed');
            }
        };

//判断是否开通小程序并返回小程序二维码
        function whetherOpen() {
            var store_id = "{$id}";
            $.ajax({
                url: "{:url('v322/web/getXcxCode','','')}",
                type: 'POST',
                data: {
                    store_id: store_id,
                    scene: 'store_id=' + store_id + '&is_share=1',
                    page: 'packageB/pages/shareRed/shareRed'
                },
                dataType: 'JSON',
                success: function (res) {
                    var data = JSON.parse(res);
                    if (data.code == 0) {
                        var imgsrc = 'data:image/jpeg;base64,' + data.data;
                        dialog.alert(imgsrc)
                    } else {
                        //去操作
                        window.location.href="{:url('index/sweepcode',['id'=>$id,'share_id'=>$share_id])}";
                    }
                },
                fail: function (error) {
                    weui.alert('抱歉出了一个错误');
                }
            })
        }
    </script>
</html>